package com.nzx.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 功能描述：通用时间工具类
 *
 * @author niezhuxe
 * @date 2021/11/5 0:15
 */
public class DateUtil {


    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    public static final String YYYY_MM_DD = "yyyy-MM-dd";

    public static final String HH_MM_SS = "HH:mm:ss";

    public static final String Y_M_D_HH_MM_SS = "yyyy年MM月dd日 HH:mm:ss";

    public static final String Y_M_D = "yyyy年MM月dd日";


    /**
     * 获取指定格式的日期字符串
     * @param date 时间
     * @param dateFormat 时间格式
     * */
    public static String getDateStrByFormat(Date date,String dateFormat){

        SimpleDateFormat sf = new SimpleDateFormat(dateFormat);
        String dateStr = null;
        try{
            dateStr = sf.format(date);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dateStr;
    }
}
